package tuling;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * Created by xsls on 2019/6/10.
 */
// @Aspect
@Component
@Order(2)
public class TulingLogAspect2 {


	@Pointcut("execution(* tuling.TulingCalculate.*(..))")
	public void pointCut(){};
	@Before(value = "pointCut()")
	public void methodBefore(JoinPoint joinPoint) throws Throwable {
		String methodName = joinPoint.getSignature().getName();
		System.out.println("22执行目标方法【"+methodName+"】的<前置通知>,入参"+ Arrays.asList(joinPoint.getArgs()));
	}

	@After(value = "pointCut()")
	public void methodAfter(JoinPoint joinPoint) {
		String methodName = joinPoint.getSignature().getName();
		System.out.println("22执行目标方法【"+methodName+"】的<后置通知>,入参"+Arrays.asList(joinPoint.getArgs()));
	}


	@AfterReturning(value = "pointCut()",returning = "result")
	public void methodReturning11(JoinPoint joinPoint, Object result) {
		String methodName = joinPoint.getSignature().getName();
		System.out.println("22执行目标方法【"+methodName+"】的<返回通知>,入参"+Arrays.asList(joinPoint.getArgs()));
	}





	@AfterThrowing(value = "pointCut()")
	public void methodAfterThrowing(JoinPoint joinPoint) {
		String methodName = joinPoint.getSignature().getName();
		System.out.println("22执行目标方法【"+methodName+"】的<异常通知>,入参"+Arrays.asList(joinPoint.getArgs()));
	}



	@Around(value = "pointCut()")
	public Object logMethodExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
		System.out.println("22执行目标方 around start");
		long startTime = System.currentTimeMillis();

		// 执行原始方法
		Object result = joinPoint.proceed();

		long endTime = System.currentTimeMillis();
		long executionTime = endTime - startTime;

		System.out.println("22执行目标方 around end");
		System.out.println("22222" + joinPoint.getSignature() + " ExecutionTime执行时间：" + executionTime + "毫秒");

		return result;
	}








}
